# Contributor: Aleks Bunin <alpinelinux@compuix.com>
# Maintainer: Aleks Bunin <alpinelinux@compuix.com>
pkgname=delta
pkgver=0.17.0
pkgrel=2
pkgdesc="Syntax-highlighting pager for git and diff output"
url="https://dandavison.github.io/delta/"
license="MIT"
# s390x: incompatible with nix crate
arch="all !s390x"
makedepends="
	cargo
	cargo-auditable
	libgit2-dev
	oniguruma-dev
	"
subpackages="
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/dandavison/delta/archive/refs/tags/$pkgver.tar.gz"
options="net"

# secfixes:
#   0.13.0-r0:
#     - CVE-2022-24713

export RUSTONIG_SYSTEM_LIBONIG="true"

prepare() {
	default_prepare

	# Rust target triple.
	local target=$(rustc -vV | sed -n 's/host: //p')

	# Build against system-provided libs
	mkdir -p .cargo
	cat >> .cargo/config.toml <<-EOF
		[target.$target]
		git2 = { rustc-link-lib = ["git2"] }
	EOF

	cargo fetch --target="$CTARGET" --locked
}

build() {
	cargo auditable build --release --frozen

	local i; for i in bash fish zsh; do
		./target/release/delta --generate-completion $i > target/delta.$i
	done
}

check() {
	cargo test --frozen -- --test-threads=1
}

package() {
	install -Dm755 target/release/delta -t "$pkgdir"/usr/bin/
	install -D -m644 target/delta.bash "$pkgdir"/usr/share/bash-completion/completions/delta
	install -D -m644 target/delta.fish "$pkgdir"/usr/share/fish/vendor_completions.d/delta.fish
	install -D -m644 target/delta.zsh "$pkgdir"/usr/share/zsh/site-functions/_delta
}

sha512sums="
7b3d4aa9bad2f3dc920d9855163e81813ea5467cd92939d4781ed3d896d10bb39110265d5294967c79f8451e8a6d3d4def7e42efb4064f3d5fbc5d99e5c245a6  delta-0.17.0.tar.gz
"
